const mongoose = require('mongoose');
mongoose.connect('mongodb://127.0.0.1:27017/test_db');
mongoose.connection.on('open',()=>{
    console.log('连接数据库成功');
    const bookSchema = mongoose.Schema({
        name:String,
        author:String,
        price:Number
    })
    const BookModel = mongoose.model('books',bookSchema);
    // 更新多个
//    BookModel.updateMany({name:'雪国'},{price:20},
    //更新一个
      BookModel.updateOne({name: '活着'},{price: 100},(error,data)=>{
        if(error){
            console.log('-----',error.message)
        }else{
            console.log(data)
        }
    })
})
mongoose.connection.on('error',()=>{
    console.log('连接数据库失败')
})